package com.hqyj.crmdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqyj.crmdemo.entity.Contact;
import com.hqyj.crmdemo.entity.Custmer;
import com.hqyj.crmdemo.entity.RestResult;
import com.hqyj.crmdemo.entity.SaleChance;
import com.hqyj.crmdemo.service.IContactService;
import com.hqyj.crmdemo.service.ICustmerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 何万林
 * @since 2022-10-17
 */
@RestController
@RequestMapping("/contact")
@CrossOrigin
public class ContactController {

    @Autowired
    IContactService service;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public RestResult<Contact> queryAll(String custmerId) {
        QueryWrapper<Contact> wrapper = new QueryWrapper<>();
        wrapper.eq("custmer_id",custmerId);
        List<Contact> contacts = service.queryOne(wrapper);
        return RestResult.ok(contacts);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public RestResult<Contact> add(Contact contact) {
        Boolean aBoolean = service.add(contact);
        if (aBoolean) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public RestResult<Contact> delete(Integer contactId ){
        Boolean delete = service.delete(contactId);
        if (delete) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public RestResult<Contact> update(Contact contact){
        Boolean update = service.update(contact);
        if (update) {
            return RestResult.ok("success");
        }else{
            return RestResult.ok("false");
        }
    }
}
